package queue;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

//模拟多线程下的queue是否有效果
public class Main {
    public static void main(String[] args) throws InterruptedException {
        ArrayQueue();
    }

    public static void ArrayQueue() throws InterruptedException {
        BlockingQueue<String> queue = new ArrayBlockingQueue<String>(100);
        for (int i = 0; i < 80; i++) {
            queue.add("sdasd"+i);
        }
        List<String> list = new ArrayList<>();
        queue.drainTo(list,99);

        new Thread(()->{
            for (int i = 0; i < 99; i++) {
                queue.add("======================================"+i);
                System.out.println("123123");
            }
        }).start();

        Thread.sleep(1000);

        System.out.println(list.size());
    }
}
